package com.hex.liyue.giftmodule.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.commonmodule.activity.BaseActivity;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.commonmodule.utils.L;
import com.hex.liyue.commonmodule.utils.StatusBarCompatUtils;
import com.hex.liyue.giftmodule.adapter.AdapterHarvestDetails;
import com.hex.liyue.giftmodule.bean.HarverDetailsBean;
import com.hex.liyue.giftmodule.bean.HarvesGiftsBean;
import com.hex.liyue.giftmodule.presenter.HarvesDetailsPresenter;
import com.hex.liyue.giftmodule.presenter.IDiscountDetailsView;
import com.hex.liyue.giftmodule.presenter.IHarvesDetilsGiftsView;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by WJ on 2016/6/20.
 * 收货详情界面
 */
public class HarvestDetailsActivity extends BaseActivity implements IHarvesDetilsGiftsView {
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    @Bind(R.id.tv_harves_addres)
    TextView tvAddress;
    @Bind(R.id.tv_phone)
    TextView tvPhone;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_harves_states)
    TextView mTvStates;
    @Bind(R.id.tv_harves_num)
    TextView mTvNums;
    @Bind(R.id.tv_harves_prices)
    TextView mTvPrices;
    @Bind(R.id.tv_create_date)
    TextView mTvDate;
    @Bind(R.id.rv_shopping_list)
    RecyclerView rvShoppingList;
    @Bind(R.id.iv_harves_details)
    ImageView iv_harves_details;
    private HarvesDetailsPresenter harvesDetailsPresenter;

    @Override
    protected void bindPresenter() {
        harvesDetailsPresenter = new HarvesDetailsPresenter(this);
    }

    @Override
    protected void initData(Bundle bundle) {
        String user_gift_export_id = getIntent().getStringExtra("user_gift_export_id");
        harvesDetailsPresenter.getHarvesDetialsGifts(user_gift_export_id);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_harvest_details;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        ivToobarBack.setVisibility(View.VISIBLE);
        tvToobarTitle.setText("收货详情");
    }

    @OnClick({R.id.iv_toobar_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toobar_back:
                onBackPressed();
                break;
        }
    }

    @Override
    public void showLod(String msg) {
        showLoad(HarvestDetailsActivity.this, msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(HarvestDetailsActivity.this, msg);
    }

    @Override
    public void setAdapter(HarverDetailsBean harverDetailsBean) {
//        HarvesGiftsBean.DataBean dataBean = (HarvesGiftsBean.DataBean) getIntent().getSerializableExtra("dataBean");
        L.d("WJ", "====接受=====" + harverDetailsBean.toString());
        mTvDate.setText("创建收货时间：" + DateUtils.getFormatDate(harverDetailsBean.data.delivery_time * 1000l, "yyyy-MM-dd"));
        mTvNums.setText("收货单号：" + harverDetailsBean.data.user_gift_export_id);
        mTvPrices.setText("商品金额：￥" + harverDetailsBean.data.total_cash);
        if (harverDetailsBean.data.status == 1) {
            mTvStates.setText("收货状态：待收货");
        } else if (harverDetailsBean.data.status == 2) {
            mTvStates.setText("收货状态：已收货");
        }
        tvName.setText(harverDetailsBean.data.username);
        tvPhone.setText("手机号：" + harverDetailsBean.data.mobile);
        tvAddress.setText("地址：" + harverDetailsBean.data.province + "" + harverDetailsBean.data.city + "" + harverDetailsBean.data.district + "" + harverDetailsBean.data.address);
        rvShoppingList.setLayoutManager(new LinearLayoutManager(this));
        Glide.with(LiYueApplication.getInstance())
                .load(harverDetailsBean.data.gift_list.get(0).gift_url).centerCrop().error(R.drawable.no_icon)
                .into(iv_harves_details);
        AdapterHarvestDetails adapterShoppingDetails = new AdapterHarvestDetails(harverDetailsBean.data.gift_list);
        adapterShoppingDetails.setOnItemClickListener(new AdapterHarvestDetails.OnItemClickListener() {
            @Override
            public void onItemClickListener(int position) {

            }
        });
        rvShoppingList.setAdapter(adapterShoppingDetails);
    }
}
